<?php
class ResourceController extends Zend_Controller_Action
{

	public $_redirector = null;
	
	public function init ()
	{
		
		$this->_redirector = $this->_helper->getHelper('Redirector');
		$this->_redirector->setCode(303);
		$req = $this->getRequest();
		$this->_path = $req->getPathInfo();
		$reqMime = $req->getServer('HTTP_ACCEPT');
		if (false !== strpos($reqMime, 'application/rdf+xml')) {
			$this->getResponse()->setHeader('Content-Type',
			'application/rdf+xml');
			$this->_redirectPath = $this->buildRedirectPath('rdfxml');
		} else
			if (false !== strpos($reqMime, 'application/rdf+json')) {
				$this->_redirectPath = $this->buildRedirectPath('data');
			} else {
				$this->_redirectPath = $this->buildRedirectPath('page');
			}
			
			
	}
	
	public function redirectAction ()
	{
		
		$this->_redirector->gotoURL($this->_redirectPath);
	}
	
	public function buildRedirectPath ($contentType)
	{
		
		$request = $this->getRequest();
		$module = $this->getRequest()->getModuleName();
		$redirectPath = $contentType;
		$redirectPath .= str_replace('thesis/', '', $this->_path);
		$redirectPath = str_replace('resource/', '', $redirectPath);
		return $redirectPath;
	}
}